<?php
			
	/* SVN FILE: $Id: log.php 8 2011-03-13 08:32:38Z michele.andreoletti@gmail.com $ */
	
	/**
	* Project Name : arcadia
	*
	* @author $Author: michele.andreoletti@gmail.com $
	* @version $Revision: 8 $
	* @lastrevision $Date: 2011-03-13 08:32:38 +0000 (Sun, 13 Mar 2011) $
	* @filesource $URL: http://arcadia.googlecode.com/svn/trunk/sysop/log.php $
	*/

	require_once '../include/functions.php';
	require_once '../include/const.inc.php';
	require_once '../include/auth.inc.php';
	require_once '../include/conn.inc.php';
	
	fnOnly4Sysop();
	
	$sScript = fnCurrentScript();
	$sSCRIPT_ROOT_PATH = (fnIsScriptInRoot() ? '.' : '..'); // Variabile utilizzata in template.php
	
	$sHeadContent = "
		<script type='text/javascript' src='../include/dataTables/media/js/jquery.dataTables.js'></script>
		<link type='text/css' href='../include/dataTables/media/css/demo_table.css' rel='stylesheet' />
		
		<script type='text/javascript' src='../include/jquery.prettydate.js'></script>
		
		<script type='text/javascript' src='include/user.js'></script>
		<link type='text/css' href='include/user.css' rel='stylesheet' />

		<script type='text/javascript' charset='utf-8'>
							
			$(document).ready(function() {
			
				$.prettyDate.messages = {
					now: 'adesso',
					minute: '1 minuto fa',
					minutes: $.prettyDate.template('{0} minuti fa'),
					hour: '1 ora fa',
					hours: $.prettyDate.template('{0} ore fa'),
					yesterday: 'ieri',
					days: $.prettyDate.template('{0} giorni fa'),
					weeks: $.prettyDate.template('{0} settimane fa')
				};
				
				/* Init DataTables */
				oTable = $('#log').dataTable( {
					'sDom': \"<f>rt<'dt_info'ip><'dt_length'>\",
					'oLanguage': { 'sUrl': '../include/dataTables/it_IT.txt' },		
					'bAutoWidth': false,
					'bStateSave': false,
					'bLengthChange': false,
					'bSort': false,	
					'iDisplayLength': 15,	
					'fnDrawCallback': function() {
						$('.prettydate').prettyDate();
					}
				});
				
			});

		</script>";


	$sLEFT_NAV_IMG = "appointment.png";
	$sHeaderTitle = $sTableTitle = "$sSUITE_NAME &raquo; Log";
	$sAPP_NAME = '&nbsp;';
	
	$html .= "<br/>";

	$html .= fnHtmlLogTable(array('tsWhen', 'sRemoteAddr', 'sUsername', 'sScript', 'sDescription', 'iView', 'sSelectFrom', 'sApp'));
	
	require_once('../themes/'.$sTHEME.'/template.php');
	die();

?><html><body bgcolor="#fff"></body></html>

<?php

	function fnHtmlLogTable ($aColumns) {
		
		$sQuery = fnQueryLog();
		$aData = fnGetDataFromQuery($sQuery, 'fnQueryLog()');
		
		$html = "<table class='display' id='log' cellspacing='0' cellpadding='0'>";
		
		$html .= "	<thead>
						<tr>";
		
		foreach ($aColumns as $sColumn) {
			$html .= "	<th>$sColumn</th>";
		}
		$html .= "		</tr>
					</thead>";
		
		$html .= "	<tbody>";	
		
		if (!empty($aData)) {
			
			foreach ($aData as $aRow) {
				
				$sClass = '';
				if ($aRow['sType']=='I') { $sClass = ''; }
				if ($aRow['sType']=='E') { $sClass = 'gradeE'; }
				if ($aRow['sType']=='S') { $sClass = 'gradeS'; }
				
				$html .= "	<tr class='$sClass'>";
				
				foreach ($aColumns as $sColumn) {
					
					if ($sColumn == 'tsWhen') {
						$sValue = fnHtmlTimestamp($aRow[$sColumn], false, "", false);
					
					} else if ($sColumn == 'iView' && $aRow[$sColumn] == 0) {
						$sValue = '&nbsp;';
						
					} else {
						$sValue = $aRow[$sColumn];
					
					}
	
					$html .= "	<td class='center'>$sValue</td>";
	
				}
				
				$html .= "	</tr>";		
			
			}
		
		} else {
		
			$html .= "<tr><td colspan='".(count($aColumns))."'>&nbsp;</td></tr>";
		
		}
		
		$html .= "	</tbody>";
		$html .= "</table>";
		
		return $html;
	}	

?>